package cn.echogo.framework.location;

import java.util.List;

import cn.echogo.ipart.R;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.location.Address;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationProvider;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

public class EGLocationListener implements LocationListener {
	
	private static final String tag = LocationListener.class.getSimpleName();
	
	private Context context;
	
	public EGLocationListener(Context context) {
		this.context = context;
	}

	@Override
	public void onLocationChanged(Location location) {
		if (location != null) {
			GeoPoint point = LocationUtil.getGeoPointByLocation(location);
			System.out.println("latitude = " + point.getLatitudeE6() + ", longitude = " + point.getLongitudeE6());

			if (point != null) {
				Address address = LocationUtil.getAddressByGeoPoint(context, point);
				
				String addressStr = LocationUtil.getAddressString(address);
				Toast.makeText(context, addressStr, Toast.LENGTH_SHORT).show();				
				
			}

		}
	}

	@Override
	public void onStatusChanged(String provider, int status, Bundle extras) {
		switch (status) {
		case LocationProvider.AVAILABLE:
			Log.d(tag, "AVAILABLE...");
			break;
		case LocationProvider.OUT_OF_SERVICE:
			Log.d(tag, "OUT_OF_SERVICE...");
			break;
		case LocationProvider.TEMPORARILY_UNAVAILABLE:
			Log.d(tag, "TEMPORARILY_UNAVAILABLE...");
			break;
		}
	}

	@Override
	public void onProviderEnabled(String provider) {
		Log.d(tag, "onProviderEnabled...");
	}

	@Override
	public void onProviderDisabled(String provider) {
		Log.d(tag, "onProviderDisabled...");
	}

}
